package ustc.sse;


import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;

public class PictureView extends View implements Runnable {
	private Paint mPaint = null;
	
	Bitmap mBitQQ = null;
	Bitmap mBitDeskTop = null;
	
	int miDTX = 0;
	public PictureView (Context context,Bitmap pic){
		super(context);
		mPaint = new Paint();
		miDTX = 0;
		mBitQQ = pic;
			//((BitmapDrawable)getResources().getDrawable(R.drawable.qq)).getBitmap();
		new Thread(this).start();
	}
	public static void drawImage(Canvas canvas,Bitmap blt,int x,int y,int w,int h,int bx,int by){
		Rect src = new Rect();
		Rect dst = new Rect();
		src.left = bx;
		src.top = by;
		src.right= bx +w;
		src.bottom = by+h;
		dst.left = x;
		dst.top = y;
		dst.right = x+w;
		dst.bottom = y +h;
		canvas.drawBitmap(blt, src, dst,null);
		src = null;
		dst = null;
	}
	
	public static void drawImage(Canvas canvas,Bitmap bitmap,int x,int y){
		canvas.drawBitmap(bitmap,x,y,null);
	}
	@Override
	public void run(){
		while(!Thread.currentThread().isInterrupted()){
			try{
				Thread.sleep(100);
			}
			catch(InterruptedException e){
				Thread.currentThread().interrupt();
			}
			postInvalidate();
		}
	}
	
	public  boolean onKeyDown(int keyCode,KeyEvent event){
		if(keyCode == KeyEvent.KEYCODE_DPAD_LEFT){
			if(miDTX>0){
				miDTX --;
			}
		}
		return true;
	}
	
	public boolean onTouchEvent(MotionEvent event){
		return true;
	}
	public void onDraw(Canvas canvas){
		super.onDraw(canvas);
		canvas.drawColor(Color.GRAY);
		PictureView.drawImage(canvas, mBitQQ, 0, 0);
	}

	


}
